/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.mapper;

import cn.webrx.entity.User;
import cn.webrx.entity.UserAddress;
import cn.webrx.entity.UserInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

/**
 * <p>Project: mybatis2021 - DbMapper
 * <p>Powered by webrx On 2021-07-23 08:51:21
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 15
 */
public interface DbMapper {
    public List<String> tbs();

    public List<String> tbs(String db);

    @Select("show databases")
    public List<String> dbs();

    @Select("select version()")
    public String version();

    @Select("select user,host,authentication_string,plugin from mysql.user")
    public List<Map<String, Object>> userInfo();

    @Select("select database(),user(),version(),@@datadir,@@basedir")
    public Map<String, Object> dbInfo();

    @Select("show create table ${tb}")
    public Map<String, Object> showCreateTable(String tb);


    @Select("select * from wx_user")
    @Results(id = "uu", value = {
            @Result(id = true, property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "userinfo", column = "username", one = @One(select = "sel1", fetchType = FetchType.EAGER)),
            @Result(property = "useraddress", column = "username", many = @Many(select = "sel2", fetchType = FetchType.LAZY))
    })
    public List<User> queryUserAll();

    @Select("select * from wx_userinfo where username = #{username}")
    public UserInfo sel1(String username);

    @Select("select * from wx_useraddress where username = #{username}")
    public List<UserAddress> sel2(String username);

    @Select("select * from wx_user where username = #{username}")
    @ResultMap(("uu"))
    public User queryByName(String username);
}

